﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.BL;
using VINETLIFE.DO;

namespace VINETLIFE.AdminCP
{
    public partial class ListMenu : System.Web.UI.Page
    {

        cmsMenuDO objMenu = new cmsMenuDO();
        protected void Page_Load(object sender, EventArgs e)
        {
           
                tlMenu.DataSource = new cmsMenuBL().SelectAll(); 
                tlMenu.DataBind();
                tlMenu.ExpandToLevel(3);
                //Ultility.ddlDatabinder(ddlType, "", "", new cmsMenuBL().SelectAll());
        }

        protected void tlMenu_StartNodeEditing(object sender, DevExpress.Web.ASPxTreeList.TreeListNodeEditingEventArgs e)
        {
            int id = 0;
            if (int.TryParse(tlMenu.EditingNodeKey, out id))
            {
                Response.Redirect("Menu.aspx?MenuID=" + id.ToString());
            }
        }

        protected void tlMenu_NodeDeleted(object sender, DevExpress.Web.Data.ASPxDataDeletedEventArgs e)
        {
            new cmsMenuBL().Delete(new cmsMenuDO() { MenuID = int.Parse(tlMenu.FocusedNode.Key) });
            Response.Redirect("ListMenu.aspx");
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("Menu.aspx");
        }

        protected string ReturnType(object e)
        {
            string sReturn = "";
            try
            {
                int type = int.Parse(e.ToString());
                if (type == 1)
                    sReturn = "<span style='color:Red;font-weight:bold;'>Top Menu</span>";
                else if (type == 2)
                    sReturn = "<span style='color:Green;font-weight:bold;'>Main Menu</span>";
                else if (type == 3)
                    sReturn = "<span style='color:#e08920;font-weight:bold;'>Menu Left</span>";
                else if (type == 4)
                    sReturn = "<span style='color:black;font-weight:bold;'>Menu Mobile</span>";
                else if (type == 5)
                    sReturn = "<span style='color:blue;font-weight:bold;'>Menu Footer Mobile</span>";
            }
            catch
            {
            }
            return sReturn;
        }

        protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
        {

            int Type = int.Parse(ddlType.SelectedValue);
            if (Type != 0)
            {
                objMenu.Type = Type;
                tlMenu.DataSource = new cmsMenuBL().Selectmenu(Type);
                tlMenu.DataBind();
            }
            else {
                tlMenu.DataSource = new cmsMenuBL().SelectAll();
                tlMenu.DataBind();
                tlMenu.ExpandToLevel(3);
            }
        }
        
    }
}